package cn.wolfcode.wolf2w.listener;

import cn.wolfcode.wolf2w.domain.Userfavor;
import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.service.IUserfavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisDataInitListeners implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private IUserfavorService userfavorService;
    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        System.out.println("初始化开始");
        //redis的初始化操作
         //1、获取所有userfavos对象
        List<Userfavor> list = userfavorService.list();
        for (Userfavor userfavor : list) {
           strategyStatisVORedisService.getFavors(userfavor.getUsid(),userfavor.getFavors());
        }
        System.out.println("初始化完成");
    }
}
